package com.titar.robot.base;

import android.text.TextUtils;

import org.jetbrains.annotations.NotNull;

import java.io.Serializable;

import static com.titar.robot.Constants.RET_SUCCESS_0;

public class BaseModel<T extends Serializable> implements Serializable {
    public int errcode = RET_SUCCESS_0;
    public String errmsg = "success";
    public T data = null;

    public int getErrcode() {
        return errcode;
    }

    public void setErrcode(int errcode) {
        this.errcode = errcode;
    }

    public String getErrmsg() {
        return errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "BaseModel{" +
                "errcode=" + errcode +
                ", errmsg='" + errmsg + '\'' +
                ", data=" + data +
                '}';
    }

    /**
     * 构建一个key
     *
     * @param apiKey 接口
     * @param id     该字段可有可无，根据接口上传参数确定
     * @return key
     */
    public static String genKey(@NotNull String apiKey, String id) {
        String key = apiKey.replace('/', '_');
        if (!TextUtils.isEmpty(id)) {
            key += "_" + id;
        }
        return key;
    }
}
